package
{
	import flash.display.Bitmap;
	import flash.display.BitmapData;
	import flash.display.GradientType;
	import flash.display.Graphics;
	import flash.display.InterpolationMethod;
	import flash.display.SpreadMethod;
	import flash.display.Sprite;
	import flash.display.StageAlign;
	import flash.display.StageScaleMode;
	import flash.events.Event;
	import flash.filters.BevelFilter;
	import flash.filters.BitmapFilter;
	import flash.filters.BitmapFilterType;
	import flash.geom.Matrix;
	import flash.geom.Rectangle;

	public class AS3Animation extends Sprite
	{
		public function AS3Animation()
		{
			trace(stage.stageWidth);
//			if (stage)
//			{
//				init();
//			}
//			else
//			{
//				this.addEventListener(Event.ADDED_TO_STAGE, init);
//			}

//			var sp:Sprite=new Sprite();
//			var g:Graphics=sp.graphics;
//			g.lineStyle(1);
//			var matr:Matrix=new Matrix();
//			matr.createGradientBox(20, 20, 45, 5, 5);
////			g.beginGradientFill(GradientType.LINEAR,[0xff0000,0xffff00],[0.2,1],[0x00, 0xFF],matr,SpreadMethod.PAD,InterpolationMethod.RGB,0);
//			g.lineGradientStyle(GradientType.LINEAR, [0xff0000, 0xffff00], [0.2, 1], [0x00, 0xFF], matr, SpreadMethod.PAD, InterpolationMethod.RGB, 0);
//			g.drawRect(0, 0, 100, 100);
//			g.endFill();
//			sp.x=sp.y=100;
//			this.addChild(sp);
			
			var sp:Sprite=new Sprite();
			var g:Graphics=sp.graphics;
			g.beginFill(0x00FFFF);
			g.drawCircle(0,0,100);
			g.endFill();
			this.addChild(sp);
			var filter:BitmapFilter = new BevelFilter(5,45,0x000000,0.25,0.5,0.3,3,3,1,1,BitmapFilterType.INNER,false);
			sp.filters = [filter];
			sp.x = sp.y=100;

//			var fillType:String = GradientType.LINEAR;
//			var colors:Array = [0xFF0000, 0x0000FF];
//			var alphas:Array = [1, 1];
//			var ratios:Array = [0x00, 0xFF];
//			var matr:Matrix = new Matrix();
//			matr.createGradientBox(20, 20, 0, 0, 0);
//			var spreadMethod:String = SpreadMethod.PAD;
//			this.graphics.beginGradientFill(fillType, colors, alphas, ratios, matr, spreadMethod);        
//			this.graphics.drawRect(0,0,100,100);


//			var str:String="132{0}";
//			var reg:RegExp=/\{0\}/g;
//			str=str.replace(new RegExp("\\{0]\}"), "aa");
//			trace(str);
//			var text:TextField=new TextField();
//			text.htmlText="aaa<br>bbb";
//			this.addChild(text);
		}

		private function init(event:Event=null):void
		{
			// draw a bunch of random lines
			graphics.lineStyle(0);
			for (var i:int=0; i < 100; i++)
			{
				graphics.lineTo(Math.random() * 300, Math.random() * 400);
			}
			// create an opaque bitmap
			var bmpd1:BitmapData=new BitmapData(300, 200, false, 0xffffff);
			bmpd1.fillRect(new Rectangle(100, 50, 100, 100), 0xff0000);
			var bmp1:Bitmap=new Bitmap(bmpd1);
			addChild(bmp1);
			// create a transparent bitmap
			var bmpd2:BitmapData=new BitmapData(300, 200, true, 0x00ffffff);
			bmpd2.fillRect(new Rectangle(100, 50, 100, 100), 0x80ff0000);
			var bmp2:Bitmap=new Bitmap(bmpd2);
			bmp2.y=200;
			addChild(bmp2);
		}

		private function addedToStageHandler(event:Event=null):void
		{
			this.removeEventListener(Event.ADDED_TO_STAGE, addedToStageHandler);
			stage.scaleMode=StageScaleMode.NO_SCALE;
			stage.align=StageAlign.TOP_LEFT;

			for (var angle:Number=0; angle < 2 * Math.PI; angle+=.1)
			{
				trace(Math.sin(angle));
				var g:Graphics=this.graphics;
				g.beginFill(0xFF0000);
				g.drawCircle(10 * angle, Math.sin(angle) * 10, 3);
				g.endFill();
			}
		}
	}
}